clear
*** note  replace the below locations by your own
*** if  you use the original data from pew
use "C:\Local\tco55\Dropbox (UC Enterprise)\robots\pewdata.dta" 
keep auto1a auto1b auto1c auto1d auto1e weight auto2 auto3 job5a job5b job5c job5d sex age race educ2 emplnw emptype1 emptype2 emptype3

*** the above leads to the smaller dataset which I posted on dataverse
use "C:\Local\tco55\Dropbox (UC Enterprise)\robots\Robots dataset for replication.dta" 

*************** ****************************creating sample and variables********************************
*a.	Your employer finds someone who is willing to do your job for less money

tab auto1a

keep if auto1a<5

*b.	You aren’t able to keep up with the technical skills required to do your job

tab auto1b

keep if auto1b<5

*c.	Your employer uses machines or computer programs to replace human workers

tab auto1c

keep if auto1c<5

*d.	Your overall industry is shrinking

tab auto1d

keep if auto1d<5

*e.	The company that you work for is poorly managed

tab auto1e

keep if auto1e<5


* fear is dummy that takes 1 if auto1 is 1 or 2

svyset [pweight = weight]

gen feara=cond(auto1a<3,1,0)
tab feara
gen fearb=cond(auto1b<3,1,0)
tab fearb
gen fearc=cond(auto1c<3,1,0)
tab fearc
gen feard=cond(auto1d<3,1,0)
tab feard
gen feare=cond(auto1e<3,1,0)
tab feare




* now long term fear

*ASK IF EMPLOYED (EMPLNW=1,2,5):
* AUTO2	Thinking about the job or occupation that you work in now, how likely do you think it is that job will exist in its current form in 50 years? Do you think it will definitely exist, probably exist, probably NOT exist, or definitely will NOT exist? {New}
*1	Definitely will exist
*2	Probably will exist
*3	Probably will NOT exist
*4	Definitely will NOT exist
*8	(VOL.) Don’t know
* 9	(VOL.) Refused
tab auto2
keep if auto2<5

* to keep sign same
gen fearlong=cond(auto2>2,1,0)
tab fearlong
* now general fear

*ASK ALL:
*AUTO3	Overall, how likely do you think it is that in the next 50 years, robots and computers will do much of the work currently done by humans? Do you think this will definitely happen, will probably happen, will probably NOT happen, or will definitely not happen? {New}
*1	Definitely happen
*2	Probably happen
*3	Probably NOT happen
*4	Definitely NOT happen
*8	(VOL.) Don’t know
*9	(VOL.) Refused
tab auto3
*keep if auto3<5

* to keep sign same
gen feargeneral=cond(auto3<3,1,0)
tab feargeneral

* sum of all fears
egen  fearsum=rowtotal(feara fearb fearc feard feare fearlong feargeneral)
egen  fearoth=rowtotal(feara fearb feard feare)
gen fearother1=cond(fearoth>0,1,0)

*a.	Your job involves a great deal of personal interaction with customers or clients
tab job5a 
gen jobamissing=cond(job5a>2,1,0)

*keep if job5a<3
*b.	Your job requires specialized technical knowledge
tab job5b 
gen jobbmissing=cond(job5b>2,1,0)

*keep if job5b<3
*c.	Your job requires creativity
tab job5c
gen jobcmissing=cond(job5c>2,1,0)

*keep if job5c<3
*d.	Your job requires that you do the same things over and over
tab job5d
gen jobdmissing=cond(job5d>2,1,0)

*keep if job5d<3


* make 0-1 dummies
replace job5a=0 if job5a>1
replace job5b=0 if job5b>1
replace job5c=0 if job5c>1
replace job5d=0 if job5d>1





* adding additional variables
* gender, 1 is male
tab sex
replace sex=0 if sex==2

* age - delete 98 (dont know) and 99(refused)

replace age=98 if age==99
gen agemissing=cond(age>97,1,0)

*keep if age<98

* race
tab race
* there are enough white and black, rest aggregate into other (including dk, refuse) 

replace race=3 if race>2

* educ2
tab educ2
*1	Less than high school (Grades 1-8 or no formal schooling)
*2	High school incomplete (Grades 9-11 or Grade 12 with NO diploma)
*3	High school graduate (Grade 12 with diploma or GED certificate)

* given few 1 and 2, make them 3
replace educ2=3 if educ2<3


*4	Some college, no degree (includes some community college)
*5	Two year associate degree from a college or university
* given less than 100 in 5 put 4 and 5 together 

replace educ2=4 if educ2==5

*6	Four year college or university degree/Bachelor’s degree (e.g., BS, BA, AB)
*7	Some postgraduate or professional schooling, no postgraduate degree
* given few 7's
replace educ2=6 if educ2==7

*8	Postgraduate or professional degree, including master’s, doctorate, medical or law degree (e.g., MA, MS, PhD, MD, JD)
*98	Don’t know
*99	Refused
* drop 98 and 99
replace educ2=98 if educ2==98
replace educ2=98 if educ2==99

* keep if educ2<10

tab educ2



*i.emplnw i.emptype1 i.jobtype
* emplnw - note we only have data for employed - hence do not know to what extent the unemployed fear the robots
*1	Employed full-time
*2	Employed part-time
* 5	(VOL.) Have own business/self-employed
* note there are a small nr of self employed - we add them to full time

replace emplnw=1 if emplnw==5

tab emplnw

* EMPTYPE1	How would you describe the place where you work? [READ]
*1	A large corporation
*2	A medium-size company
*3	A small business
*4	A part of the federal, state or local government
*5	A school or educational institution, OR
*6	A non-profit organization?
*7	(VOL.) Other
* few of 7's but not clear where to add them - in general, hard to merge these categories
*8	(VOL.) Self-employed/work at home
* merge 8 with 3 since few in 8 and self employed is typically small business
replace emptype1=3 if emptype1==8

*98	(VOL.) Don’t know
*99	(VOL.) Refused
* drop dont know

replace emptype1=98 if emptype1==99

*keep if emptype1<10
tab emptype1


* we merge the next two variables - manual and physical labor becomes 0
*EMPTYPE2	Would you say that the type of work you do primarily involves manual and physical labor, or not?
*1	Yes, involves manual and physical labor
*2	No, does not
*8	(VOL.) Don’t know
*9	(VOL.) Refused

replace emptype3=0 if emptype2==1
*ASK IF JOB IS NOT MANUAL LABOR/DK/REFUSED (EMPTYPE2=2-9)
*EMPTYPE3	Which of the following best describes the type of work that you do? [READ]
*1	Professional
*2	Manager or executive
*3	Government official
*very few 3 - add to 6
*4	Administrative or clerical, OR
*5	Customer service?
*6	(VOL.) Other (SPECIFY)
* few 6
*8	(VOL.) Don’t know
*9	(VOL.) Refused
* delete 8 and 9
replace emptype3=6 if emptype3==3

replace emptype3=8 if emptype3==9

*keep if emptype3<7
tab emptype3

*************************************************************** making categories -more if less fear


foreach i in a b c d e{

gen fear`i'cat=.
replace fear`i'cat=1 if auto1`i'==4
replace fear`i'cat=2 if auto1`i'==3
replace fear`i'cat=3 if auto1`i'==2
replace fear`i'cat=4 if auto1`i'==1
}
tab fearacat

* find highest level of 
egen fearothercat=rowmax(fearacat fearbcat feardcat fearecat)
gen fearother=cond(fearothercat>2,1,0)

gen fearlongcat=auto2
gen feargeneralcat=auto3


***************************************************** analysis
* descriptive stats of fears
svy:tab auto1c

* note this one has higher as more fear while the others it's the opposite
svy: tab fearothercat

svy: tab auto1a
svy: tab auto1b
svy:tab auto1d
svy:tab auto1e
svy: tab fearothercat

*svy: tab fearother

* note minimum is max fear
egen minfearwithoutrobots=rowmin(auto1a auto1b auto1d auto1e)
svy:tab minfearwithoutrobots auto1c, cell

svy:tab auto2
*svy:tab auto3


svy:tab auto1c auto2
svy:tab fearlong if fearc==0
svy:tab fearlong fearc, cell



* descriptive stats of job characteristics
svy:tab job5a
svy:tab job5b
svy:tab job5c
svy:tab job5d

gen countchar=job5a+job5b+job5c+job5d
svy:tab countchar







*************************************************************** regression analysis - main table 4
svy: oprobit fearccat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table1

svy: oprobit fearccat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table2


svy: oprobit fearothercat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table3

svy: oprobit fearothercat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table4


svy: oprobit fearlongcat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table5

svy: oprobit fearlongcat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table6



esttab fearreg5table*  using "C:\Local\tco55\Dropbox\robots\robots stata oporbit.rtf", b(%12.3f) se(%12.3f) star(* 0.10 ** 0.05 *** 0.01) ar2 nogaps label onecell modelwidth(5) replace



***** robustness

*******

*************************************************************** regression analysis - OLS
svy: reg fearccat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store fearreg5table1

svy: reg fearccat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store fearreg5table2


svy: reg fearothercat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store fearreg5table3

svy: reg fearothercat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store fearreg5table4


svy: reg fearlongcat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store fearreg5table5

svy: reg fearlongcat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store fearreg5table6



esttab fearreg5table*  using "C:\Local\tco55\Dropbox\robots\robots stata ols.rtf", b(%12.3f) se(%12.3f) star(* 0.10 ** 0.05 *** 0.01) ar2 nogaps label onecell modelwidth(5) replace


*************************************************************** regression analysis - not wieghted
oprobit fearccat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table1

oprobit fearccat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table2


oprobit fearothercat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table3

oprobit fearothercat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table4

oprobit fearlongcat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table5

oprobit fearlongcat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table6



esttab fearreg5table*  using "C:\Local\tco55\Dropbox\robots\robots stata oporbit nonw.rtf", b(%12.3f) se(%12.3f) star(* 0.10 ** 0.05 *** 0.01) ar2 nogaps label onecell modelwidth(5) replace

***** probit


*************************************************************** regression analysis
svy: probit fearc job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table1

svy: probit fearc job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table2


svy: probit fearother job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table3

svy: probit fearother job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table4

svy: probit fearlong job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
margins, dydx(*) post
est store fearreg5table5

svy: probit fearlong job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
margins, dydx(*) post
est store fearreg5table6



esttab fearreg5table*  using "C:\Local\tco55\Dropbox\robots\robots stata porbit .rtf", b(%12.3f) se(%12.3f) star(* 0.10 ** 0.05 *** 0.01) ar2 nogaps label onecell modelwidth(5) replace




*************************************************************** regression analysis with ordered probit coefficients rather than marginal effects
svy: oprobit fearccat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store anfearreg5table1

svy: oprobit fearccat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store anfearreg5table2


svy: oprobit fearothercat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store anfearreg5table3

svy: oprobit fearothercat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store anfearreg5table4


svy: oprobit fearlongcat job5a job5b job5c job5d jobamissing jobbmissing jobcmissing jobdmissing
est store anfearreg5table5

svy: oprobit fearlongcat job5a job5b job5c job5d sex age i.race i.educ2 i.emplnw i.emptype1 i.emptype3 jobamissing jobbmissing jobcmissing jobdmissing agemissing
est store anfearreg5table6



esttab anfearreg5table*  using "C:\Local\tco55\Dropbox\robots\robots stata oporbit annex.rtf", b(%12.3f) se(%12.3f) star(* 0.10 ** 0.05 *** 0.01) ar2 nogaps label onecell modelwidth(5) replace



